<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function arr(words) {
      let w = words.map(_ => _.split(''))
      for (let i = w.length - 1; i > 0; i--)
        if ([...w[i]].sort().join('') === [...w[i - 1]].sort().join(''))
          w.splice(i, 1)
      return w.map(_ => _.join(''))
    };
    console.log(arr(words = ["abba", "baba", "bbaa", "cd", "cd"]));
  </script>
</body>

</html>